import http from './interface'

//设置baseUrl
http.config.baseUrl = "http://192.168.0.115:18082/api"  //测试
// http.config.baseUrl = "http://192.168.0.182:18082/api" //蒙哥
// http.config.baseUrl = "http://192.168.0.183:18082/api"

import RongIMLib from '@/static/js/IMSDK/RongIMLib-3.0.7-dev.js'
const im = RongIMLib.init({ appkey: 'qf3d5gbjq9qxh' });

//设置请求前拦截器
http.interceptor.request = (config) => {
	uni.showLoading({title:'加载中...'})
	//添加通用参数
	config.upType == "formdata" ?  //改变请求头为formData类型提交
		config.header = {
		    "Token": localStorage.token || null,
			"Content-Type":"application/x-www-form-urlencoded"
		}
	:
		config.header = {
		    "Token": localStorage.token || null,
		}
}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	const returnCode = response.data.returnCode
    //判断返回状态 执行相应操作
	if(returnCode == 1000){
		// uni.showToast({title: response.data.message?response.data.message:'登录超时',icon:'none',duration:1500});
		setTimeout(()=>{
			localStorage.removeItem('userInfo')
			im.disconnect().then(function() {
				console.log('断开链接成功');
			});
			toLogin()
		},1000)
	}
	uni.hideLoading()
    return response;
}
//上传图片
export const uploadImg = (formData) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: http.config.baseUrl + '/File/uploadImg',
			formData,
			header: {
				'Token':localStorage.token,
			},
			success: function(res) {
				resolve(JSON.parse(res.data));
			},
			fail: function(res) {
				reject(JSON.parse(res.data))
			},
		})
	});
}

// 健康管理师列表
export const healthList = (data) => { return http.request({ url: '/HealthExpert/getExpertList', method: 'POST', upType:'formdata', data })}
// 日常监测
export const healthMonitorDetail = () => {return http.request({url: '/AppMonitor/detile?token='+localStorage.token,method: 'get'})}
// 验证手机号
export const verifyMobile = (phone) => {return http.request({url: `/Account/verifyMobile?phone=${phone}`,method: 'post'})}
// 发送验证码
export const sedNote = (phone,type) => {return http.request({url: `/Verification/sedNote?phone=${phone}&type=${type}`,method: 'post', })}
// 注册
export const register = (data) => {return http.request({url: `/Account/register`,method: 'post', data})}
// 帐号密码登录
export const login = (data) => {return http.request({url: `/Account/login`,method: 'post', data})}
// 验证码登录
export const codeLogin = (data) => {return http.request({url: `/Account/codeLogin`,method: 'post', data})}
// 实名认证
export const upAuthentication = (data) => {return http.request({url: `/Account/upAuthentication`,method: 'post', data})}
// 退出登录
export const logout = (data) => {return http.request({url:'/Account/logout',method: 'post'})}
// 重置密码
export const resetPassword = (data) => {return http.request({url:'/Account/resetPassword',method: 'post',data})}
// 获取用户信息
export const getUserInfo = (data) => {return http.request({url:'/Account/getUserInfo',method: 'post'})}
// 修改登录密码
export const updatePassword = (data) => {return http.request({url:'/Account/updatePassword',upType:'formdata',method:'post',data})}
// 验证密码
export const verificationPassword = (data) => {return http.request({url:'/Account/verificationPassword',upType:'formdata',method: 'post',data})}
// 修改用户信息
export const upUserInfo = (data) => {return http.request({url:'/Account/upUserInfo',method: 'post',data})}
// 获取健康管理师列表
export const UserHealth = (data) => { return http.request({url:'/UserHealth/list',method: 'GET',data})}
// 修改个人基本信息
export const UserInfoupdate = (id,data) => {return http.request({url:`/UserInfo/update/${id}`,method: 'post',data})}
// 修改个人基本信息
export const UserInfolist = (data) => {return http.request({url:'/UserInfo/list',method: 'get',data})}
// 查看基本信息详情
export const UserInfoDetails = (data) => {return http.request({url:'/UserInfo/details',method: 'get',data})}
// 获取用户基本信息
export const findById = () => {return http.request({url:'/UserInfo/findById',method: 'get'})}
// 新增基本信息
export const userInfoAdd = (data) => {return http.request({url: '/UserInfo/add',method: 'post', data})}
// 个人基本信息列表
// export const UserInfofindById = (id) => {return http.request({url:`/UserInfo/findById/${id}`,method: 'get'})}
//删除个人基本信息
export const UserinforDeleteId = (id) => {return http.request({url:`/UserInfo/delete/${id}`,method: 'post'})}
// 编辑个人基本信息
export const userinforUpdate = (data) => {return http.request({url:'/UserInfo/update',method: 'post',data})}
// 干预方案列表
export const interveneSchemeList = (data) => {return http.request({url:'/interveneScheme/list',method: 'get',data})}
// 干预方案查详情
export const interveneSchemeInfo = (id) => {return http.request({url:`/interveneScheme/info/${id}`,method: 'get'})}
// 干预计划方案列表
export const InterventionPlanPlanList = (data) => {return http.request({url:`/health/InterventionPlan/planList`,method: 'get',data})}
// 干预计划列表
export const InterventionPlanList = (data) => {return http.request({url:`/health/InterventionPlan/list`,method: 'get',data})}
// 干预方案详情
export const InterventionPlandetails = (id) => {return http.request({url:`/health/InterventionPlan/details/${id}`,method: 'get'})}
//IM获取token
export const IMgetUserToken = (data) => { return http.request({url: '/sms/getUserToken',method: 'get',data}) }
//保存计算转化分 中医体质
export const questionnaireSave = (data) => {return http.request({url:'/AppConstitutionQuestionnaire/save',method: 'post',data})}
//修改转化分 中医体质
export const questionnaireUpdate = (data) => {return http.request({url:'/AppConstitutionQuestionnaire/update',method: 'post',data})}
//获取列表页  中医体质
export const questionnaireList = (data) => {return http.request({url:'/AppConstitutionQuestionnaire/list',method: 'get',data})}
//中医体检删除
export const questionnaireDel = (id) => {return http.request({url:`/AppConstitutionQuestionnaire/delete/${id}`,method: 'post'})}
// 中医体检详情
export const questionnaireInfoId = (id) => {return http.request({url:`/AppConstitutionQuestionnaire/info/${id}`,method: 'get'})}
//望问切详情
export const chineseMedicineDetails = (id) => {return http.request({url:'/AppConstitutionQuestionnaire/chineseMedicineDetails?id='+id,method: 'get'})}
//获取群组成员
export const groupMembers = (data) => {return http.request({url: `/sms/groupMembers`,method: 'get',data})}
//关注健康管理师
export const addHealth = (data) => {return http.request({url:`/UserHealth/addHealth`,method: 'post',data})}
//取消关注健康管理师
export const cancelHealth = (uhId) => {return http.request({url:`/UserHealth/cancelHealth/${uhId}`,method: 'post'})}
// 中医体质是否有未评估的问卷
export const getIsConversion = () => {return http.request({url: '/AppConstitutionQuestionnaire/getIsConversion',method: 'get'})}
//获取健康管理师详情
export const findByHealth = (data) => {return http.request({url: `/UserHealth/findByHealth`,method: 'get',data})}
//获取系统配置项列表和单个数据
export const DataDictfindByType = (data) => {return http.request({url: `/DataDict/findByType`,method: 'get',data})}
// 获取问卷模版
export const getQuestionnaireStencil = (data) => {return http.request({url: '/Questionnaire/getQuestionnaireStencil',method: 'get',data})}
// 问卷详情
export const Questionnairefind = (id,data) => {return http.request({url: `/Questionnaire/findBy/${id}`,method: 'get',data})}
// 新增问卷答案
export const addQuestionnaire = (data) => {return http.request({url: `/Questionnaire/addQuestionnaire`,method: 'post',data})}
// 问卷列表
export const Questionnairelist = (data) => {return http.request({url: `/Questionnaire/list`,method: 'get',data})}
// 健康管理师编辑问卷答案
export const updateAppQuestionnaire = (id,data) => {return http.request({url: `/Questionnaire/updateAppQuestionnaire/${id}`,method: 'post',data})}
// 评估列表详情
export const HealthRisksList = (data) => {return http.request({url: '/HealthRisks/list',method: 'get',data})}
//健康风险评估汇总详情
export const healthRisksId = (id) => {return http.request({url: `/HealthRisks/info/${id}?type=3`,method: 'get'})}
// 添加体检报告
export const Medicalinsert = (data) => {return http.request({url: `/Medical/insert`,method: 'POST',data})}
// 获取体检报告列表
export const MedicalList = (data) => {return http.request({url: '/Medical/list',method: 'get',data})}
// 获取体检报告详情
export const MedicalfindbyId = (id) => {return http.request({url: `/Medical/findBy/${id}`,method: 'get'})}
// 编辑体检报告
export const Medicalupdate = (data) => {return http.request({url: `/Medical/update`,method: 'POST',data})}
// 获取体检报告模版
export const getReportTemplateStencil = () => {return http.request({url: '/Medical/getReportTemplateStencil',method: 'get'})}
//删除体检报告
export const MedicaldelId = (id) => {return http.request({url: `/Medical/del/${id}`,method: 'post'})}
//查询体检报告--或体检报告详情
export const findByMedical = (number) => {return http.request({url: `/Medical/findByReport/${number}`,method: 'get'})}
//获取最新用户基本信息
export const newestUserInfo = () => {return http.request({url: `/UserInfo/newestUserInfo`,method: 'get'})}
// 获取最新的添加问卷
export const newestQuestionnaire = (data) => {return http.request({url: `/Questionnaire/newestQuestionnaire`,method: 'get',data})}
// 查询最新添加的体检报告
export const newestMedical = (data) => {return http.request({url: `/Medical/newestMedical`,method: 'get',data})}
// 申请评估
export const Assessinsert = (data) => {return http.request({url: `/Assess/insert`,method: 'post',data})}
// 评估列表
export const Assesslist = (data) => {return http.request({url: `/Assess/list`,method: 'get',data})}
// 健康监测列表
export const AppMonitorList = (id) => {return http.request({url: '/AppMonitor/list?id='+id,method: 'get'})}
//监测数据
export const AppMonitorDetile = () => {return http.request({url: '/AppMonitor/detile',method: 'get'})}
//监测数据 新增
export const AppMonitorSave = (data) => {return http.request({url: '/AppMonitor/save',method: 'post',data})}
//饮食新增
export const AppDietRecordSave = (data) => {return http.request({url: '/AppDietRecord/save',method: 'post',data})}
//饮食列表
export const AppDietRecordList = (data) => {return http.request({url: '/AppDietRecord/list',method: 'get',data})}
// 饮食删除
export const AppDietRecordDelete = (id) => {return http.request({url: '/AppDietRecord/delete?id='+id,method: 'post'})}
//删除问卷
export const QuestionnaireDelete = (id) => {return http.request({url: `/Questionnaire/del/${id}`,method: 'post'})}
//饮食详情
export const AppDietRecordInfo = (id) => {return http.request({url: `/AppDietRecord/info/${id}`,method: 'get'})}
//用药记录  新增
export const AppDrugsRecordSave = (data) => {return http.request({url: '/AppDrugsRecord/save',method: 'post',data})}
//用药记录  列表
export const AppDrugsRecordList = (data) => {return http.request({url: '/AppDrugsRecord/list',method: 'get',data})}
//用药记录 删除
export const AppDrugsRecordDelete = (id) => {return http.request({url: `/AppDrugsRecord/delete/${id}`,method: 'post'})}
//用药记录  详情
export const AppDrugsRecordInfo = (id) => {return http.request({url: `/AppDrugsRecord/findByDrugs/${id}`,method: 'get'})}
//用药记录  修改
export const AppDrugsRecordUpdate = (id,data) => {return http.request({url: `/AppDrugsRecord/update/${id}`,method: 'post',data})}
//就医记录  新增
export const AppMedicalRecordsSave = (data) => {return http.request({url: '/AppMedicalRecords/save',method: 'post',data})}
//就医记录  列表
export const AppMedicalRecordsList = (data) => {return http.request({url: '/AppMedicalRecords/list',method: 'get',data})}
//就医记录  删除
export const AppMedicalRecordsDelete = (id) => {return http.request({url: `/AppMedicalRecords/delete/${id}`,method: 'post'})}
//就医记录  详情
export const AppMedicalRecordsInfo = (id) => {return http.request({url: `/AppMedicalRecords/findByRecords/${id}`,method: 'get'})}
//就医记录  编辑
export const AppMedicalRecordsUpdate = (id,data) => {return http.request({url: `/AppMedicalRecords/update/${id}`,method: 'post',data})}
//随访记录  列表
export const AppFollowUpRecordsList = (data) => {return http.request({url: '/AppFollowUpRecords/list',method: 'get',data})}
//随访记录  详情
export const AppFollowUpRecordsInfo = (id) => {return http.request({url: `/AppFollowUpRecords/detaile/${id}`,method: 'get'})}
//随访记录  评价
export const AppMedicalRecordsUpdateByEvaluate = (data) => {return http.request({url: `/AppFollowUpRecords/updateByEvaluate`,method: 'post',data})}
//转诊记录  列表
export const AppHealthReferralRecordsList = (data) => {return http.request({url: `/AppHealthReferralRecords/list`,method: 'get',data})}
//转诊记录  详情
export const AppHealthReferralRecordsInfo = (id) => {return http.request({url: `/AppHealthReferralRecords/info/${id}`,method: 'get'})}
//服务通知列表
export const messageNoticeList = (data) => {return http.request({url: `/messageNotice/list`,method: 'get',data})}
//科普文章列表
export const Articlelist = (data) => {return http.request({url: `/Article/list`,method: 'get',data})}
// 科普文章分类列表
export const ArticleTypelist = () => {return http.request({url: `/AdArticlelType/list`,method: 'get'})}
//科普文章  详情
export const ArticleInfo = (id) => {return http.request({url: `/Article/info/${id}`,method: 'get'})}
// getOpenId
export const getOpenId = (code) => {return http.request({url: `/authorize/getOpenId?code=${code}`,method: 'post'})}
// 微信登陆
export const authorizeLogin = (data) => {return http.request({url: `/authorize/wxLogin`,method: 'post',data})}
// 手机号验证
export const authorizeVerifyMobile = (data) => {return http.request({url: `/authorize/verifyMobile`,method: 'post',data})}
// 绑定手机号
export const authorizebindPhone = (data) => {return http.request({url: `/authorize/bindPhone`,method: 'post',data})}
//问卷
export const psychologyQuestion = (data) => {return http.request({url: `/healthTopics/findByTopicsType?${data}`,method: 'get'})}
//心理健康问卷 新增
export const psychologyQuestionAdd= (data) => {return http.request({url: `/AppMentalHealthAssessment/add`,method: 'post',data})}
//心理健康问卷  列表
export const psychologyQuestionList = (data) => {return http.request({url: `/AppMentalHealthAssessment/list`,method: 'get',data})}
//心理健康问卷  删除
export const psychologyQuestionDel= (id) => {return http.request({url: `/AppMentalHealthAssessment/delete/${id}`,method: 'post'})}
//心理健康问卷  详情
export const psychologyQuestionInfo= (id) => {return http.request({url: `/AppMentalHealthAssessment/details/${id}`,method: 'get'})}
//心理健康问卷 编辑
export const psychologyQuestionUpdate= (data) => {return http.request({url: `/AppMentalHealthAssessment/update`,method: 'post',data})}
//心理健康问卷  更改状态
export const psychologyQuestionStatus= (id,status) => {return http.request({url: `/AppMentalHealthAssessment/updateByStetus/${id}?status=${status}`,method: 'post'})}
// 健康现状  查询是否有未签发文件
export const mentalHealthAssessmentFindBy= (userId) => {return http.request({url: `/AppMentalHealthAssessment/findByStatus/${userId}`,method: 'get'})}
//获取所有体检列表
export const getReportTemplateStencilPage= (data) => {return http.request({url: `/Medical/getReportTemplateStencilPage`,method: 'get',data})}
//新增体检报告
export const HealthExaminationReportSave= (data) => {return http.request({url: `/HealthExaminationReport/save`,method: 'post',data})}
//修改体检报告
export const HealthExaminationReportUpdate= (data) => {return http.request({url: `/HealthExaminationReport/update`,method: 'post',data})}
//体检报告列表
export const HealthExaminationReportList= (data) => {return http.request({url: `/HealthExaminationReport/list`,method: 'get',data})}
//体检报告删除
export const HealthExaminationReportDel= (id) => {return http.request({url: `/HealthExaminationReport/delete/${id}`,method: 'post'})}
//体检报告详情
export const HealthExaminationReportDetails= (id) => {return http.request({url: `/HealthExaminationReport/details?id=${id}`,method: 'get'})}
//体检报告申请评估
export const HealthExaminationReportStatus= (id,status) => {return http.request({url: `/HealthExaminationReport/updateByStatus/?id=${id}&status=${status}`,method: 'post'})}
//健康现状汇总列表
// export const appHealthAssessSummaryList= (data) => {return http.request({url: `/appHealthAssessSummary/`,method: 'get',data})}
export const appHealthAssessSummaryList= (data) => {return http.request({url: `/appAssessSummary/`,method: 'get',data})}
//健康现状汇总详情
export const appHealthAssessSummaryDetail= (id) => {return http.request({url: `/appAssessSummary/${id}`,method: 'get'})}
//健康现状  中医计算转化分
export const AppMentalHealthAssessmentRefresh= (data) => {return http.request({url: `/AppMentalHealthAssessment/refresh`,method: 'post',data})}
//未来疾病 新增
export const appSicknessDangeAdd= (data) => {return http.request({url: `/appSicknessDange/add`,method: 'post',data})}
//未来疾病  列表
export const appSicknessDangeList= (data) => {return http.request({url: `/appSicknessDange/`,method: 'get',data})}
//未来疾病  删除
export const appSicknessDangeDelete= (id) => {return http.request({url: `/appSicknessDange/delete/${id}`,method: 'post'})}
//未来疾病  详情
export const appSicknessDangeDetail= (id) => {return http.request({url: `/appSicknessDange/${id}`,method: 'get'})}
//未来疾病  修改
export const appSicknessDangeUpdate= (data) => {return http.request({url: `/appSicknessDange/update`,method: 'post',data})}
//未来疾病  修改状态
export const appSicknessDangeByStatus= (id,status) => {return http.request({url: `/appSicknessDange/updateByStetus/${id}?status=${status}`,method: 'post'})}
//未来疾病  糖尿病新增
export const appDiseaseDangeAdd= (data) => {return http.request({url: `/appDiseaseDange/`,method: 'post',data})}
//未来疾病  糖尿病列表
export const appDiseaseDangeList= (data) => {return http.request({url: `/appDiseaseDange/`,method: 'get',data})}
//未来疾病  糖尿病详情
export const appDiseaseDangeDetail= (id) => {return http.request({url: `/appDiseaseDange/${id}`,method: 'get'})}
//未来疾病  糖尿病修改
export const appDiseaseDangeUpdate= (data) => {return http.request({url: `/appDiseaseDange/edit`,method: 'post',data})}
//未来疾病  糖尿病修改状态
export const appDiseaseDangeByStatus= (id,status) => {return http.request({url: `/appDiseaseDange/${id}/apply?status=${status}`,method: 'post'})}
//未来疾病  糖尿病删除
export const appDiseaseDangeDelete= (id) => {return http.request({url: `/appDiseaseDange/${id}`,method: 'post'})}
// 获取所有异常列表
export const getReportAbnormalPage = (data) => {return http.request({url: `/Medical/getReportAbnormalPage`,method: 'get',data})}





//获取wx图片
export const getImage = (serverId) => {return http.request({url: `/wx/getImage?serverId=`+serverId,method: 'post'})}



function toLogin (){
	uni.redirectTo({url:'/pages/login/login'});
}


export default {
	healthList,
	healthMonitorDetail,
	verifyMobile,
	sedNote,
	register,
	login,
	codeLogin,
	upAuthentication,
	logout,
	resetPassword,
	getUserInfo,
	updatePassword,
	verificationPassword,
	upUserInfo,
	uploadImg,
	UserHealth,
	UserInfoupdate,
	UserInfolist,
	UserInfoDetails,
	findById,
	userInfoAdd,
	UserinforDeleteId,
	userinforUpdate,
	interveneSchemeList,
	interveneSchemeInfo,
	InterventionPlanPlanList,
	InterventionPlanList,
	InterventionPlandetails,
	questionnaireSave,
	questionnaireUpdate,
	questionnaireList,
	questionnaireDel,
	questionnaireInfoId,
	chineseMedicineDetails,
	addHealth,
	cancelHealth,
	getIsConversion,
	findByHealth,
	IMgetUserToken,
	groupMembers,
	DataDictfindByType,
	getQuestionnaireStencil,
	Questionnairefind,
	addQuestionnaire,
	Questionnairelist,
	updateAppQuestionnaire,
	HealthRisksList,
	healthRisksId,
	Medicalinsert,
	MedicalList,
	MedicalfindbyId,
	Medicalupdate,
	getReportTemplateStencil,
	findByMedical,
	newestUserInfo,
	newestQuestionnaire,
	newestMedical,
	Assessinsert,
	Assesslist,
	AppMonitorList,
	AppMonitorDetile,
	AppMonitorSave,
	AppDietRecordSave,
	AppDietRecordList,
	AppDietRecordDelete,
	AppDietRecordInfo,
	AppDrugsRecordSave,
	AppDrugsRecordList,
	AppDrugsRecordDelete,
	AppDrugsRecordInfo,
	AppDrugsRecordUpdate,
	AppMedicalRecordsSave,
	AppMedicalRecordsList,
	AppMedicalRecordsDelete,
	AppMedicalRecordsInfo,
	AppMedicalRecordsUpdate,
	messageNoticeList,
	AppFollowUpRecordsList,
	AppFollowUpRecordsInfo,
	AppMedicalRecordsUpdateByEvaluate,
	AppHealthReferralRecordsList,
	AppHealthReferralRecordsInfo,
	Articlelist,
	ArticleInfo,
	ArticleTypelist,
	getOpenId,
	authorizeLogin,
	authorizeVerifyMobile,
	authorizebindPhone,
	QuestionnaireDelete,
	MedicaldelId,
	getImage,
	psychologyQuestion,
	psychologyQuestionAdd,
	psychologyQuestionList,
	psychologyQuestionDel,
	psychologyQuestionInfo,
	psychologyQuestionUpdate,
	psychologyQuestionStatus,
	getReportTemplateStencilPage,
	HealthExaminationReportSave,
	HealthExaminationReportUpdate,
	HealthExaminationReportList,
	HealthExaminationReportDel,
	HealthExaminationReportDetails,
	HealthExaminationReportStatus,
	appHealthAssessSummaryList,
	appHealthAssessSummaryDetail,
	AppMentalHealthAssessmentRefresh,
	appSicknessDangeAdd,
	appSicknessDangeList,
	appSicknessDangeDelete,
	appSicknessDangeDetail,
	appSicknessDangeUpdate,
	appSicknessDangeByStatus,
	appDiseaseDangeAdd,
	appDiseaseDangeList,
	appDiseaseDangeDetail,
	appDiseaseDangeUpdate,
	appDiseaseDangeByStatus,
	appDiseaseDangeDelete,
	mentalHealthAssessmentFindBy,
	getReportAbnormalPage
}